var yz_pay = require('../../../mycomponent/yz_pay/yz_pay');
var app = getApp();
import logs from "../../../utils/logs";
Page({
  behaviors: [yz_pay],
  data: {
    language: '',
    order_id: "",
    goodList: [],
    totalNum: 0,
    totalPrice: '',
    order_sn: '',
    orderData: null,

    balance: 0,
    payParams: '',
    info_form: {},
    money: '',
    buttons: [],
    pay_sn: '订单编号',
    order_pay_id: '',
    mid: '',
    payerImg: '',
    payerName: '',
    pid: '',
    share_type:1,
  },

  confirm(e) {
    let type = e.currentTarget.dataset.value;
    let btn = e.currentTarget.dataset.btn;
    this.handlePay(btn, type);
  },

  //获取代付会员信息和支付信息
  getPayerInfo: function() {
    var that = this;
    var _url = app.getNetAddresss("order.merge-pay.anotherPayOrder");
    _url += "&order_ids=" + that.data.order_id + '&mid=' + that.data.mid;
    _url += '&pid=' + that.data.pid;
    app._getNetWork({
      url: _url,
      success: function(response) {
        //var _data = res.data.data;
        if (response.data.result == 1) {
          var rs = response.data.data;
          that.setData({
            payerImg: rs.member.avatar,
            payerName: rs.member.nickname,
            order_pay_id: rs.order_pay.id,
            buttons: rs.buttons,
            totalPrice:rs.order_pay.amount
          });
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'none',
            duration: 2000,
            success: function() {
              // wx.reLaunch({
              //   url: '/packageG/index/index'
              // });
            },
            fail: function() {}
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
  },
  getOrderDetail: function() {
    var that = this;
    var _url = app.getNetAddresss("order.another-pay-detail");
    _url += "&order_id=" + that.data.order_id + '&mid=' + that.data.mid;
    _url += '&pid=' + that.data.pid;
    app._getNetWork({
      url: _url,
      success: function(response) {
        //var _data = res.data.data;
        console.log("ressss::::", response);
        if (response.data.result == 1) {
          // 从另外的接口获取
          // var totalPrice = 0;
          // for (var i in response.data.data) {
          //   for (var j in response.data.data[i].has_many_order_goods) {
          //     totalPrice += parseFloat(response.data.data[i].has_many_order_goods[j].price);
          //   }
          // }

          that.setData({
            goodList: response.data.data,
            //	totalPrice: totalPrice.toFixed(2),
          });
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'none',
            duration: 2000
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
  },

  onLoad: function(options) {
    var that = this;
    console.log('options:', options);
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        let info_arr = [];
        info_arr = scene.split(",");
        for (let i = 0; i < info_arr.length; i++) {
          let chil_arr = [];
          chil_arr = info_arr[i].split("=");
          if (chil_arr[0] == "t") {
            this.setData({
              share_type:chil_arr[1]
            })
          }
          if(chil_arr[0] == "id"){
            this.setData({
              order_id:chil_arr[1]
            })
          }
          if(chil_arr[0] == "p"){
            this.setData({
              pid:chil_arr[1],
            })
            logs.info('----------app.js->packageD\buy\payanotherDetail\payanotherDetail.js代付绑定的上级mid->143-----------',chil_arr[1])
            app._setMid(chil_arr[1])
            this.setData({
              mid : chil_arr[1]
            })
          }
        }
      }
    }else{
      that.setData({
        order_id: options.id,
        pid: options.p
      });
      if(options.p){
        logs.info('----------app.js->packageD\buy\payanotherDetail\payanotherDetail.js代付绑定的上级mid->143-----------',options.p)
        app._setMid(options.p)
        this.setData({
          mid:options.p
        })
      }
      if(options.share_type == 2){
        this.setData({
          share_type:options.share_type
        })
      }
    }
    // mid: options.mid,
    // let _mid = wx.getStorageSync('yz_uid');
    // this.setData({
    //   mid: _mid,
    // })

    this.getPayerInfo();
    this.getOrderDetail();

  },

  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
    // 页面渲染完成
  },
});
